<template>
	<view class="page-fade-in" :style="{opacity: pageOpc}">
		<template v-if="pageOpc">
			<view class="content">
				<!-- <view class="nav-box flexWrap">
					<view class="nav-item flexWarpCenterColumn" :class="{active:currmentIndex==1}" @tap="changeNav(1)">
						<text>乒乓球定价</text>
						<text class="nav-line"></text>
					</view>
					<view class="nav-item flexWarpCenterColumn" :class="{active:currmentIndex==2}" @tap="changeNav(2)">
						<text>麻将定价</text>
						<text class="nav-line"></text>
					</view>
				</view> -->
				<block v-if="currmentIndex==1">
					<view class="shop-info-box">
						<view class="sticky-box">
							<view class="info-item flexWrapNo">
								<view class="item-title">乒乓球可预约：</view>
								<input placeholder="请输入天数" placeholder-class="placeholderclass"
									v-model="store_info.days_in_advance" type="number" />
								<view class="flexWrapNo">
									<picker @change="bindPickerChange" :data-index="0" :value="advanceIndex" :range="array">
										<view class="uni-input">{{array[advanceIndex]}}</view>
									</picker>
									<text class="icon-more"></text>
								</view>
							</view>
							<view class="remaks-box" @tap="goPage('/pages/manage/limitationSetting')">
								备注:更多精细预约设置请在预约管理中设置<text class="icon-more"></text>
							</view>
							<view class="info-item flexWrap Noborder">
								<view class="flexWrapNo" style="flex: 1;">
									<view>台桌类型：</view>
									<picker @change="changeTable" :value="tableIndex" :range="tableList" range-key="name">
										<view class="uni-input">{{tableList[tableIndex].name}}</view>
									</picker>
								</view>
								<text class="icon-more"></text>
							</view>
						</view>
						<view class="price-box">
							<view class="info-item flexWrapNo Noborder noPadd" v-if="tableIndex==0">
								<view class="item-title">标准单价：</view>
								<input placeholder="请输入单价" placeholder-class="placeholderclass" v-model="store_info.price"
									type="digit" />
								元
							</view>
							<view class="info-item flexWrapNo Noborder noPadd"  v-if="tableIndex==0">
								<view class="item-title">标准单位：</view>
								<input placeholder="" placeholder-class="placeholderclass"
									v-model="store_info.reference_unit" type="number" placeholder="请输入单位"/>
								分钟
							</view>
							<view class="info-item flexWrapNo Noborder noPadd"  v-if="tableIndex==1">
								<view class="item-title">标准单价：</view>
								<input placeholder="请输入单价" placeholder-class="placeholderclass"
									v-model="store_info.jq_price" type="digit" />
								元
							</view>
							<view class="info-item flexWrapNo Noborder noPadd"  v-if="tableIndex==2">
								<view class="item-title">标准单价：</view>
								<input placeholder="请输入单价" placeholder-class="placeholderclass"
									v-model="store_info.slk_price" type="digit" />
								元/小时
							</view>
							<view class="meal-box" style="margin-top: 0;">
								<block v-for="(item,index) in mealArr" :key="index">
									<view class="info-item flexWrapNo">
										<view class="item-title">套餐名称：</view>
										<input placeholder="请输入套餐名称" placeholder-class="placeholderclass"
											v-model="item.p_name" maxlength="50" />
									</view>
									<view class="info-item flexWrapNo">
										<view class="item-title">套餐时长：</view>
										<input placeholder="请输入整数" placeholder-class="placeholderclass"
											v-model="item.duration" type="number" />
										分钟
									</view>
									<view class="info-item flexWrapNo">
										<view class="item-title">套餐价格：</view>
										<input placeholder="请输入价格" placeholder-class="placeholderclass"
											v-model="item.p_price" type="digit" />
										元
									</view>
									<view class="info-item flexWrapNo" style="align-items: center;">
										<view class="item-title">使用限制：</view>
										<view class="textarea">
											{{item.usage_restrictions==1?'不限制':item.usage_restrictions==2?'仅设置时间内可用':'仅设置时间内不可用'}}
										</view>
										<text class="set" @tap="goSet(index)">设置</text>
									</view>
									<view class="info-item flexWrapNo" style="border-bottom: none;">
										<view class="item-title">套餐说明：</view>
										<textarea placeholder="请输入套餐说明" placeholder-class="placeholderclass"
											v-model="item.p_tx_sm" style="color: #82819B;" disabled></textarea>
									</view>
									<view class="info-item flexWrapNo" style="border-bottom: none;">
										<view class="item-title">补充说明：</view>
										<textarea placeholder="请输入套餐补充说明" placeholder-class="placeholderclass"
											v-model="item.supplement"></textarea>
									</view>
									<view class="remaks-box" style="margin-top:0;text-decoration: none;">
										重要提示：补充说明中请勿输入功能性内容，如无法判定内容是否为功能性说明可联系客服。
									</view>
									<view class="btn-box flexWrap">
										<view @tap="moveUp(index)">上移</view>
										<view @tap="moveDown(index)">下移</view>
										<view @tap="delItem(index)">删除</view>
									</view>
								</block>
								<view @tap="addItem()" class="add-btn">增加套餐</view>
							</view>
						</view>
						<view class="price-box" v-for="(item,index) in priceList" :key="index">
							<view class="info-title">自定义价格</view>
							<view class="info-item flexWrapNo Noborder noPadd">
								<view class="item-title">计费名称：</view>
								<input placeholder="请输入计费名称" placeholder-class="placeholderclass"
									v-model="item.name" maxlength="50" />
							</view>
							<view class="info-item flexWrapNo Noborder noPadd">
								<view class="item-title">单价：</view>
								<input placeholder="请输入单价" placeholder-class="placeholderclass"
									v-model="item.unit_price" type="digit" />
								元/小时
							</view>
							<view class="info-title">自定义套餐</view>
							<view class="meal-box">
								<block v-for="(packageitem,packageindex) in item.mealArr" :key="packageindex">
									<view class="info-item flexWrapNo">
										<view class="item-title">套餐名称：</view>
										<input placeholder="请输入套餐名称" placeholder-class="placeholderclass"
											v-model="packageitem.title" maxlength="50" />
									</view>
									<view class="info-item flexWrapNo">
										<view class="item-title">套餐时长：</view>
										<input placeholder="请输入整数" placeholder-class="placeholderclass"
											v-model="packageitem.duration" type="number" />
										分钟
									</view>
									<view class="info-item flexWrapNo">
										<view class="item-title">套餐价格：</view>
										<input placeholder="请输入价格" placeholder-class="placeholderclass"
											v-model="packageitem.price" type="digit" />
										元
									</view>
									<view class="info-item flexWrapNo" style="align-items: center;">
										<view class="item-title">使用限制：</view>
										<view class="textarea">
											{{packageitem.usage_restrictions==1?'不限制':packageitem.usage_restrictions==2?'仅设置时间内可用':'仅设置时间内不可用'}}
										</view>
										<text class="set" @tap="priceGoset(index,packageindex)">设置</text>
									</view>
									<view class="info-item flexWrapNo" style="border-bottom: none;">
										<view class="item-title">套餐说明：</view>
										<textarea placeholder="请输入套餐说明" placeholder-class="placeholderclass"
											v-model="packageitem.package_description" style="color: #82819B;" disabled></textarea>
									</view>
									<view class="info-item flexWrapNo" style="border-bottom: none;">
										<view class="item-title">补充说明：</view>
										<textarea placeholder="请输入套餐补充说明" placeholder-class="placeholderclass"
											v-model="packageitem.supplement"></textarea>
									</view>
									<view class="remaks-box" style="margin-top:0;text-decoration: none;">
										重要提示：补充说明中请勿输入功能性内容，如无法判定内容是否为功能性说明可联系客服。
									</view>
									<view class="btn-box flexWrap">
										<view @tap="pricemoveUp(index,packageindex)">上移</view>
										<view @tap="pricemoveDown(index,packageindex)">下移</view>
										<view @tap="priceDelItem(index,packageindex)">删除</view>
									</view>
								</block>
								<view @tap="addPriceMeal(index)" class="add-btn">增加套餐</view>
							</view>
							<view class="btn-box flexWrap Noborder">
								<view class="add-btn" @tap="delPrice(index)">删除</view>
								<!-- <view class="add-btn" @tap="addPrice()">自定义价格</view> -->
							</view>
						</view>
						<!-- <view class="add-btn" @tap="addPrice()">自定义价格</view> -->
					</view>
				</block>
				<block v-if="currmentIndex==2">
					<view class="shop-info-box">
						<view class="info-title">规则设置</view>
						<view class="info-item flexWrapNo">
							<view class="item-title">最低预定时长：</view>
							<input placeholder="请输入整数" placeholder-class="placeholderclass"
								v-model="store_info.minimum_reservation_time" type="number" />
							小时
						</view>
						<view class="info-item flexWrapNo">
							<view class="item-title">最低续费时长：</view>
							<input placeholder="请输入整数" placeholder-class="placeholderclass"
								v-model="store_info.minimum_renewal_duration" type="number" />
							小时
						</view>
						<view class="info-item flexWrapNo">
							<view class="item-title">麻将可预约：</view>
							<input placeholder="请输入天数" placeholder-class="placeholderclass"
								v-model="store_info.advance_appointment_day" type="number" />
							<view class="flexWrapNo">
								<picker @change="bindPickerChange" :data-index="1" :value="mjIndex" :range="array">
									<view class="uni-input">{{array[mjIndex]}}</view>
								</picker>
								<text class="icon-more"></text>
							</view>
						</view>
						<view class="remaks-box" @tap="goPage('/pages/manage/limitationSetting')">
							备注:更多精细预约设置请在预约管理中设置<text class="icon-more"></text>
						</view>
						<block v-for="(item,index) in mjList" :key="index">
							<view class="info-title">包房设置价格</view>
							<view class="info-item flexWrapNo">
								<view class="item-title">包房名称：</view>
								<input placeholder="请输入包房名称" placeholder-class="placeholderclass" v-model="item.name"
									maxlength="50" />
							</view>
							<view class="info-item flexWrapNo">
								<view class="item-title">单价：</view>
								<input placeholder="请输入单价" placeholder-class="placeholderclass"
									v-model="item.unit_price" type="digit" />
								元
							</view>
							<view class="info-item flexWrapNo">
								<view class="item-title">续费单价：</view>
								<input placeholder="请输入续费单价" placeholder-class="placeholderclass"
									v-model="item.renew_price" type="digit" />
								元
							</view>
							<view class="info-title">包房套餐设置</view>
							<view class="meal-box">
								<block v-for="(packageitem,packageindex) in item.mealArr" :key="packageindex">
									<view class="info-item flexWrapNo">
										<view class="item-title">套餐名称：</view>
										<input placeholder="请输入套餐名称" placeholder-class="placeholderclass"
											v-model="packageitem.title" />
									</view>
									<view class="info-item flexWrapNo">
										<view class="item-title">套餐时长：</view>
										<input placeholder="请输入整数" placeholder-class="placeholderclass"
											v-model="packageitem.duration" type="number" />
										小时
									</view>
									<view class="info-item flexWrapNo">
										<view class="item-title">套餐价格：</view>
										<input placeholder="请输入价格" placeholder-class="placeholderclass"
											v-model="packageitem.price" type="digit" />
										元
									</view>
									<view class="info-item flexWrapNo" style="align-items: center;">
										<view class="item-title">使用限制：</view>
										<view class="textarea">
											{{packageitem.usage_restrictions==1?'不限制':packageitem.usage_restrictions==2?'仅设置时间内可用':'仅设置时间内不可用'}}
										</view>
										<text class="set" @tap="mjGoset(index,packageindex)">设置</text>
									</view>
									<view class="info-item flexWrapNo" style="border-bottom: none;">
										<view class="item-title">套餐说明：</view>
										<textarea placeholder="请输入套餐说明" placeholder-class="placeholderclass"
											v-model="packageitem.package_description" style="color: #82819B;"
											disabled></textarea>
									</view>
									<view class="info-item flexWrapNo" style="border-bottom: none;">
										<view class="item-title">补充说明：</view>
										<textarea placeholder="请输入套餐补充说明" placeholder-class="placeholderclass"
											v-model="packageitem.supplement"></textarea>
									</view>
									<view class="remaks-box" style="margin-top:0;text-decoration: none;">
										重要提示：补充说明中请勿输入功能性内容，如无法判定内容是否为功能性说明可联系客服。
									</view>
									<view class="btn-box flexWrap">
										<view @tap="mjmoveUp(index,packageindex)">上移</view>
										<view @tap="mjmoveDown(index,packageindex)">下移</view>
										<view @tap="mjDelItem(index,packageindex)">删除</view>
									</view>
								</block>
								<view class="add-btn" @tap="addRoomMeal(index)">增加套餐</view>
							</view>
							<view class="mj-btn  flexWrap">
								<view @tap="delRoom(index)">删除</view>
								<view @tap="addRoom()">增加包房</view>
							</view>
						</block>
						<view class="mj-btn  flexWrap" v-if="mjList.length==0">
							<view @tap="addRoom()">增加包房</view>
						</view>
					</view>
				</block>
				<view class="bottom-box flexWrapNo">
					<view class="define-btn" @tap="fixPriceSetCanDoFunction()">提交保存</view>
				</view>

				<!--操作指引悬浮按钮 -->
				<guideline :path="'moduleB/manage/priceSet'"></guideline>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageOpc: 0,
				currmentIndex: 1,
				mealArr: [{
					tableIndex: 0
				}],
				array: ['天', '小时', '分钟'],
				mjIndex: 0,
				advanceIndex: 0,
				tableList: [{
						name: "乒乓球",
						value: 1
					},
					// {
					// 	name: "美式九球",
					// 	value: 2
					// },
					// {
					// 	name: "斯诺克",
					// 	value: 3
					// }
				],
				tableIndex: 0,
				store_info: {
					reference_unit:""
				},
				mjList: [{
					name: ""
				}],
				priceList:[]
			}
		},
		onLoad() {
			this.fixPriceSet();
		},
		onReady() {
			setTimeout(() => {
				this.pageOpc = 1
			}, 100)
		},
		methods: {
			changeTable(e) {
				console.log(e)
				this.tableIndex = e.detail.value
				this.fixPriceSet();
			},
			changeNav(index) {
				this.currmentIndex = index
				this.fixPriceSet();
			},
			goSet(index) {
				uni.setStorageSync('usage_restrictions', this.mealArr[index].usage_restrictions)
				uni.setStorageSync('set_time', this.mealArr[index].set_time)
				this.goPage('/moduleB/manage/useLimitSet?index=' + index + '&type=' + this.currmentIndex)
			},
			mjGoset(roomIndex, packgeIndex) {
				let usage_restrictions = this.mjList[roomIndex].mealArr[packgeIndex].usage_restrictions
				let set_time = this.mjList[roomIndex].mealArr[packgeIndex].set_time
				uni.setStorageSync('usage_restrictions', usage_restrictions)
				uni.setStorageSync('set_time', set_time)
				this.goPage('/moduleB/manage/useLimitSet?roomIndex=' + roomIndex + '&type=' + this.currmentIndex +
					'&packgeIndex=' + packgeIndex)
			},
			priceGoset(priceIndex, packgeIndex) {
				let usage_restrictions = this.priceList[priceIndex].mealArr[packgeIndex].usage_restrictions
				let set_time = this.priceList[priceIndex].mealArr[packgeIndex].set_time
				uni.setStorageSync('usage_restrictions', usage_restrictions)
				uni.setStorageSync('set_time', set_time)
				this.goPage('/moduleB/manage/useLimitSet?priceIndex=' + priceIndex + '&type=3'+
					'&packgeIndex=' + packgeIndex)
			},
			addItem() {
				let set_time = [{
						"week": "0",
						"name": "周一",
						"starttime": "08:00",
						"endtime": "12:00"
					},
					{
						"week": "0",
						"name": "周二",
						"starttime": "08:00",
						"endtime": "12:00"
					},
					{
						"week": "0",
						"name": "周三",
						"starttime": "08:00",
						"endtime": "12:00"
					},
					{
						"week": "0",
						"name": "周四",
						"starttime": "08:00",
						"endtime": "12:00"
					},
					{
						"week": "0",
						"name": "周五",
						"starttime": "08:00",
						"endtime": "12:00"
					},
					{
						"week": "0",
						"name": "周六",
						"starttime": "08:00",
						"endtime": "12:00"
					},
					{
						"week": "0",
						"name": "周日",
						"starttime": "08:00",
						"endtime": "12:00"
					}
				]
				let item = {
					p_name: "",
					duration: '',
					p_price: "",
					p_tx_sm: `1、优惠套餐，开台后不支持退款；2、不支持多次消费。`,
					supplement: "",
					table_type:Number(this.tableIndex)+1,
					table_name: "",
					tableIndex: 0,
					set_time: set_time,
					usage_restrictions: 1,
				}
				this.mealArr.push(item)
			},
			delItem(index) {
				uni.showModal({
					title: "提示",
					content:"确定删除套餐信息？",
					success: res=> {
						if (res.confirm) {
							this.mealArr.splice(index, 1)
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
				
			},
			// 增加包房
			addRoom() {
				let item = {
					name: "",
					renew_price: '',
					unit_price: "",
					mealArr: []
				}
				this.mjList.push(item)
			},
			// 
			addPrice() {
				let item = {
					name: "",
					price: '',
					mealArr: []
				}
				this.priceList.push(item)
			},
			delRoom(index) {
				// console.log(this.mjList[index].id)
				uni.showModal({
					title: '提示',
					content: '确定删除包房定价信息？',
					success: res=> {
						if (res.confirm) {
							if (this.mjList[index].id) {
								this.deleteMjRoom(index);
							} else {
								this.mjList.splice(index, 1)
							}
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});	
			},
			delPrice(index) {
				// console.log(this.priceList[index].id)
				uni.showModal({
					title: "提示",
					content: '确定删除定价信息？',
					success: res=> {
						if (res.confirm) {
							if (this.priceList[index].id) {
								this.deletePrice(index);
							} else {
								this.priceList.splice(index, 1)
							}
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});	
			},
			// 请求接口
			deleteMjRoom(index) {
				this.$request.post(this.$api.deleteMjRoom, {
					store_id: uni.getStorageSync('store_id'),
					mj_billing_rules: this.mjList[index].id
				}, {
					token: true
				}).then(res => {
					if (res.code == 1) {
						this.mjList.splice(index, 1)
					}
				})
			},
			// 请求接口
			deletePrice(index) {
				this.$request.post(this.$api.deleteTqRoom, {
					store_id: uni.getStorageSync('store_id'),
					tq_billing_rules: this.priceList[index].id
				}, {
					token: true
				}).then(res => {
					if (res.code == 1) {
						this.priceList.splice(index, 1)
					}
				})
			},
			addRoomMeal(roomIndex) {
				let set_time = [{
						"week": "0",
						"name": "周一",
						"starttime": "08:00",
						"endtime": "12:00"
					},
					{
						"week": "0",
						"name": "周二",
						"starttime": "08:00",
						"endtime": "12:00"
					},
					{
						"week": "0",
						"name": "周三",
						"starttime": "08:00",
						"endtime": "12:00"
					},
					{
						"week": "0",
						"name": "周四",
						"starttime": "08:00",
						"endtime": "12:00"
					},
					{
						"week": "0",
						"name": "周五",
						"starttime": "08:00",
						"endtime": "12:00"
					},
					{
						"week": "0",
						"name": "周六",
						"starttime": "08:00",
						"endtime": "12:00"
					},
					{
						"week": "0",
						"name": "周日",
						"starttime": "08:00",
						"endtime": "12:00"
					}
				]
				let item = {
					title: "",
					duration: "",
					package_description: `1、优惠套餐，开台后不支持退款；2、不支持多次消费。`,
					supplement: "",
					price: "",
					set_time: set_time,
					usage_restrictions: 1,
				}
				console.log(roomIndex)
				console.log(this.mjList)
				this.mjList[roomIndex].mealArr.push(item)
			},
			addPriceMeal(priceIndex) {
							let set_time = [{
									"week": "0",
									"name": "周一",
									"starttime": "08:00",
									"endtime": "12:00"
								},
								{
									"week": "0",
									"name": "周二",
									"starttime": "08:00",
									"endtime": "12:00"
								},
								{
									"week": "0",
									"name": "周三",
									"starttime": "08:00",
									"endtime": "12:00"
								},
								{
									"week": "0",
									"name": "周四",
									"starttime": "08:00",
									"endtime": "12:00"
								},
								{
									"week": "0",
									"name": "周五",
									"starttime": "08:00",
									"endtime": "12:00"
								},
								{
									"week": "0",
									"name": "周六",
									"starttime": "08:00",
									"endtime": "12:00"
								},
								{
									"week": "0",
									"name": "周日",
									"starttime": "08:00",
									"endtime": "12:00"
								}
							]
							let item = {
								title: "",
								duration: "",
								package_description: `1、优惠套餐，开台后不支持退款；2、不支持多次消费。`,
								supplement: "",
								price: "",
								set_time: set_time,
								usage_restrictions: 1,
							}
							console.log(priceIndex)
							console.log(this.priceList)
							this.priceList[priceIndex].mealArr.push(item)
						},
			moveUp(index) {
				let array = this.mealArr
				if (index == 0) {
					this.$tools.showToast('已在顶部，不能再上移')
					return;
				}
				[array[index - 1], array[index]] = [array[index], array[index - 1]];
				this.mealArr = JSON.parse(JSON.stringify(array))
			},
			moveDown(index) {
				let array = this.mealArr
				if (index === array.length - 1) {
					this.$tools.showToast('已在底部，不能再下移')
					return;
				}
				[array[index + 1], array[index]] = [array[index], array[index + 1]];
				this.mealArr = JSON.parse(JSON.stringify(array))
			},
			mjmoveUp(roomIndex, packgeIndex) {
				let array = this.mjList[roomIndex].mealArr
				if (packgeIndex == 0) {
					this.$tools.showToast('已在顶部，不能再上移')
					return;
				}
				[array[packgeIndex - 1], array[packgeIndex]] = [array[packgeIndex], array[packgeIndex - 1]];
				this.mjList[roomIndex].mealArr = JSON.parse(JSON.stringify(array))
			},
			mjDelItem(roomIndex, packgeIndex) {
				uni.showModal({
					title: "提示",
					content: '确定删除包房套餐信息？',
					success: res=> {
						if (res.confirm) {
							this.mjList[roomIndex].mealArr.splice(packgeIndex, 1)
						} else if (res.cancel) {
							// console.log('用户点击取消')
						}
					}
				});
				
			},
			mjmoveDown(roomIndex, packgeIndex) {
				let array = this.mjList[roomIndex].mealArr
				if (packgeIndex === array.length - 1) {
					this.$tools.showToast('已在底部，不能再下移')
					return;
				}
				[array[packgeIndex + 1], array[packgeIndex]] = [array[packgeIndex], array[packgeIndex + 1]];
				this.mjList[roomIndex].mealArr = JSON.parse(JSON.stringify(array))
			},
			// 自定义套餐
			pricemoveUp(priceIndex, packgeIndex) {
				let array = this.priceList[priceIndex].mealArr
				if (packgeIndex == 0) {
					this.$tools.showToast('已在顶部，不能再上移')
					return;
				}
				[array[packgeIndex - 1], array[packgeIndex]] = [array[packgeIndex], array[packgeIndex - 1]];
				this.priceList[priceIndex].mealArr = JSON.parse(JSON.stringify(array))
			},
			priceDelItem(priceIndex, packgeIndex) {
				uni.showModal({
					title: "提示",
					content: '确定删除套餐信息？',
					success: res=> {
						if (res.confirm) {
							this.priceList[priceIndex].mealArr.splice(packgeIndex, 1)
						} else if (res.cancel) {
							// console.log('用户点击取消')
						}
					}
				});
				
			},
			pricemoveDown(priceIndex, packgeIndex) {
				let array = this.priceList[priceIndex].mealArr
				if (packgeIndex === array.length - 1) {
					this.$tools.showToast('已在底部，不能再下移')
					return;
				}
				[array[packgeIndex + 1], array[packgeIndex]] = [array[packgeIndex], array[packgeIndex + 1]];
				this.priceList[priceIndex].mealArr = JSON.parse(JSON.stringify(array))
			},
			bindPickerChange: function(e) {
				let index = e.currentTarget.dataset.index
				if (index == 0) {
					this.advanceIndex = e.detail.value
					this.store_info.days_in_advance_type = Number(this.advanceIndex) + 1
				} else if (index == 1) {
					this.mjIndex = e.target.value
					this.store_info.advance_appointment_day_type = Number(this.mjIndex) + 1
				}
			},
			fixPriceSet() {
				this.$request.post(this.$api.fixPriceSet, {
					store_id: uni.getStorageSync('store_id'),
					type: this.currmentIndex,
					table_type:Number(this.tableIndex)+1
				}, {
					token: true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code == 1) {
						let set_time = [{
								"week": "0",
								"name": "周一",
								"starttime": "08:00",
								"endtime": "12:00"
							},
							{
								"week": "0",
								"name": "周二",
								"starttime": "08:00",
								"endtime": "12:00"
							},
							{
								"week": "0",
								"name": "周三",
								"starttime": "08:00",
								"endtime": "12:00"
							},
							{
								"week": "0",
								"name": "周四",
								"starttime": "08:00",
								"endtime": "12:00"
							},
							{
								"week": "0",
								"name": "周五",
								"starttime": "08:00",
								"endtime": "12:00"
							},
							{
								"week": "0",
								"name": "周六",
								"starttime": "08:00",
								"endtime": "12:00"
							},
							{
								"week": "0",
								"name": "周日",
								"starttime": "08:00",
								"endtime": "12:00"
							}
						]
						this.store_info = data.store_info
						this.mjIndex = Number(this.store_info.advance_appointment_day_type - 1)
						this.advanceIndex = Number(this.store_info.days_in_advance_type - 1)
						this.tableIndex=Number(data.table_type)-1
						console.log(this.tableIndex)
						if (this.currmentIndex == 1) { //乒乓球
							for (let i in data.store_info.set_meal) {
								if (data.store_info.set_meal[i].set_time) {
									data.store_info.set_meal[i].set_time = JSON.parse(data.store_info.set_meal[i]
										.set_time)
								} else {
									data.store_info.set_meal[i].set_time = set_time
								}
							}
							this.mealArr = data.store_info.set_meal || []
							if(data.store_info.store_tq_price_list.length!=0){
								this.priceList = data.store_info.store_tq_price_list.map(item => {
									for (let i in item.package) {
										item.package[i].set_time = item.package[i].set_time ? JSON.parse(item
											.package[i].set_time) : set_time
									}
									return {
										id: item.id,
										name: item.name,
										unit_price: item.unit_price,
										mealArr: item.package || []
									}
								})
								console.log(this.priceList)
							}else{
								this.priceList=[]
							}
						} else {
							//麻将
							this.mjList = data.store_info.store_mj_price_list.map(item => {
								for (let i in item.package) {
									item.package[i].set_time = item.package[i].set_time ? JSON.parse(item
										.package[i].set_time) : set_time
								}
								return {
									id: item.id,
									name: item.name,
									unit_price: item.unit_price,
									renew_price: item.renew_price,
									mealArr: item.package || []
								}
							})
						}
					}
				})
			},
			fixPriceSetCanDoFunction() {
				console.log('点击了')
				this.$jiuaiDebounce.canDoFunction({
					key: 'fixPriceSetPro', //基于此值判断是否可以操作，如两个方法传入了同样的key，则会混淆，建议传入调用此事件的方法名，简单好梳理
					time: 2000, //如果传入time字段，则为定时器后，自动解除锁定状态，单位（毫秒）
					success: () => { //成功中调用应该操作的方法，被锁定状态不会执行此代码块内的方法
						this.fixPriceSetPro();
					}
				})
			},
			fixPriceSetPro() {
				let requestData = {

				}
				let mealArr = this.mealArr
				if (this.currmentIndex == 1) {
					if (!this.store_info.price || this.store_info.price == 0) {
						this.$tools.showToast('请设置正确的价格')
						return;
					}
					if (!this.store_info.reference_unit || this.store_info.reference_unit == 0) {
						this.$tools.showToast('请设置正确的单位')
						return;
					}
					if (this.store_info.days_in_advance > 3 && this.store_info.days_in_advance_type == 1) {
						this.$tools.showToast('可预约时间最多可设置3天');
						return;
					}
					if (this.store_info.days_in_advance > 72 && this.store_info.days_in_advance_type == 2) {
						this.$tools.showToast('可预约时间最多可设置72小时');
						return;
					}
					if (this.store_info.days_in_advance > 4320 && this.store_info.days_in_advance_type == 3) {
						this.$tools.showToast('可预约时间最多可设置4,320分钟');
						return;
					}
					if (!this.store_info.days_in_advance) {
						this.$tools.showToast('请填写可预约时间');
						return;
					}
					for (let i in mealArr) {
						mealArr[i].set_time = JSON.stringify(mealArr[i].set_time)
						if (!mealArr[i].p_name) {
							this.$tools.showToast('套餐名称不能为空')
							return;
						}
						if (this.$tools.containsWildcard(mealArr[i].p_name)) {
							this.$tools.showToast('套餐名称不能包含特殊字符')
							return;
						}
						if (!mealArr[i].p_price) {
							this.$tools.showToast('套餐价格不能为空')
							return;
						}
						// if (mealArr[i].duration < 1 || mealArr[i].duration > 12) {
						// 	this.$tools.showToast('套餐时长为1-12')
						// 	return;
						// }
						if (!this.$tools.isInteger(Number(mealArr[i].duration))) {
							this.$tools.showToast('套餐时长为整数')
							return;
						}
					}
					let priceList = this.priceList.map(item => {
						for (let i in item.mealArr) {
							item.mealArr[i].set_time = JSON.stringify(item.mealArr[i].set_time)
						}
						return {
							id: item.id,
							name: item.name,
							type:Number(this.tableIndex)+1,
							unit_price: item.unit_price,
							package: item.mealArr,
						}
					})
					for (let i in priceList) {
						if (!priceList[i].name) {
							this.$tools.showToast('计费名称不能为空')
							return;
						}
						if (this.$tools.containsWildcard(priceList[i].name)) {
							this.$tools.showToast('计费名称不能包含特殊字符')
							return;
						}
						if (!priceList[i].unit_price || priceList[i].unit_price == 0) {
							this.$tools.showToast('请设置正确的自定义价格')
							return;
						}
					}
					for (var i = 0; i < priceList.length; i++) {
						for (var j = 0; j < priceList[i].package.length; j++) {
							console.log(priceList[i].package[j])
							if (!priceList[i].package[j].title) {
								this.$tools.showToast('自定义套餐名称不能为空')
								return;
							}
							if (this.$tools.containsWildcard(priceList[i].package[j].title)) {
								this.$tools.showToast('自定义套餐名称不能包含特殊字符')
								return;
							}
							if (!priceList[i].package[j].price) {
								this.$tools.showToast('自定义套餐价格不能为空')
								return;
							}
							if (priceList[i].package[j].duration < 1 || priceList[i].package[j].duration > 12) {
								this.$tools.showToast('自定义套餐时长为1-12')
								return;
							}
							if (!this.$tools.isInteger(Number(priceList[i].package[j].duration))) {
								this.$tools.showToast('自定义套餐时长为整数')
								return;
							}
							if (!priceList[i].package[j].price) {
								this.$tools.showToast('自定义套餐价格不能为空')
								return;
							}
						}
					}
					requestData = {
						store_id: uni.getStorageSync('store_id'),
						type: this.currmentIndex,
						price: this.store_info.price,
						reference_unit:this.store_info.reference_unit,
						slk_price: this.store_info.slk_price,
						jq_price: this.store_info.jq_price,
						days_in_advance: this.store_info.days_in_advance,
						days_in_advance_type: this.store_info.days_in_advance_type,
						table_type:Number(this.tableIndex)+1,
						set_meal: JSON.stringify(mealArr),
						store_tq_price_list:JSON.stringify(priceList)
					}
				} else {
					if (this.store_info.minimum_reservation_time < 1 || this.store_info.minimum_reservation_time > 12) {
						this.$tools.showToast('最低预定时长为1-12')
						return;
					}
					if (this.store_info.minimum_renewal_duration < 1 || this.store_info.minimum_renewal_duration > 12) {
						this.$tools.showToast('最低续费时长为1-12')
						return;
					}
					if (this.store_info.advance_appointment_day > 3 && this.store_info.advance_appointment_day_type == 1) {
						this.$tools.showToast('可预约时间最多可设置3天');
						return;
					}
					if (this.store_info.advance_appointment_day > 72 && this.store_info.advance_appointment_day_type ==
						2) {
						this.$tools.showToast('可预约时间最多可设置72小时');
						return;
					}
					if (this.store_info.advance_appointment_day > 4320 && this.store_info.advance_appointment_day_type ==
						3) {
						this.$tools.showToast('可预约时间最多可设置4,320分钟');
						return;
					}
					let mjList = this.mjList.map(item => {
						for (let i in item.mealArr) {
							item.mealArr[i].set_time = JSON.stringify(item.mealArr[i].set_time)
						}
						return {
							id: item.id,
							name: item.name,
							unit_price: item.unit_price,
							renew_price: item.renew_price,
							package: item.mealArr
						}
					})
					for (let i in mjList) {
						if (!mjList[i].name) {
							this.$tools.showToast('包房名称不能为空')
							return;
						}
						if (this.$tools.containsWildcard(mjList[i].name)) {
							this.$tools.showToast('包房名称不能包含特殊字符')
							return;
						}
						if (!mjList[i].unit_price || mjList[i].unit_price == 0) {
							this.$tools.showToast('请设置正确的包房价格')
							return;
						}
						if (!mjList[i].renew_price || mjList[i].renew_price == 0) {
							this.$tools.showToast('请设置正确的续费价格')
							return;
						}
					}
					for (var i = 0; i < mjList.length; i++) {
						for (var j = 0; j < mjList[i].package.length; j++) {
							console.log(mjList[i].package[j])
							if (!mjList[i].package[j].title) {
								this.$tools.showToast('套餐名称不能为空')
								return;
							}
							if (this.$tools.containsWildcard(mjList[i].package[j].title)) {
								this.$tools.showToast('套餐名称不能包含特殊字符')
								return;
							}
							if (mjList[i].package[j].duration < 1 || mjList[i].package[j].duration > 12) {
								this.$tools.showToast('套餐时长为1-12')
								return;
							}
							if (!this.$tools.isInteger(Number(mjList[i].package[j].duration))) {
								this.$tools.showToast('套餐时长为整数')
								return;
							}
							if (!mjList[i].package[j].price) {
								this.$tools.showToast('套餐价格不能为空')
								return;
							}
						}
					}
					requestData = {
						store_id: uni.getStorageSync('store_id'),
						type: this.currmentIndex,
						minimum_renewal_duration: this.store_info.minimum_renewal_duration,
						minimum_reservation_time: this.store_info.minimum_reservation_time,
						advance_appointment_day: this.store_info.advance_appointment_day,
						advance_appointment_day_type: this.store_info.advance_appointment_day_type,
						store_mj_price_list: JSON.stringify(mjList)
					}
				}
				this.$request.post(this.$api.fixPriceSetPro, requestData, {
					token: true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code == 1) {
						this.$tools.showToast('修改成功')
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 1000)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		padding: 0 10upx 200upx 10upx;
	}

	.nav-box {
		padding: 20upx 74upx;
		border-bottom: 1rpx solid #36355E;
		background: #040336;
		position: sticky;
		top: 0;
		z-index: 99;

		.nav-item {
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #82819B;

			.nav-line {
				width: 86rpx;
				height: 6rpx;
				margin-top: 10upx;
			}
		}

		.active {
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;

			.nav-line {
				background: #26BCFD;
			}
		}
	}

	.mj-btn {
		padding-top: 20upx;
		justify-content: space-around;

		view {
			line-height: 70rpx;
			width: 122rpx;
			height: 70rpx;
			background: #26BCFD;
			border-radius: 16rpx;
			font-size: 24upx;
			text-align: center;
			color: #FFFFFF;
		}
	}

	.shop-info-box {
		.sticky-box{
			background: #040336;
			// position: sticky;
			top: 98upx;
			z-index: 99;
		}
		.info-title {
			text-align: center;
			font-size: 32upx;
			font-weight: bold;
			color: #FFFFFF;
			margin-top: 30upx;
		}
		.price-box{
			border: 1rpx solid #36355E;
			padding: 10upx;
			border-radius: 10upx;
			margin-top: 10upx;
		}
		.btn-box {
			border-top: 1rpx solid #36355E;
			padding-top: 10upx;
		
			view {
				line-height: 70rpx;
				width: 122rpx;
				height: 70rpx;
				background: #26BCFD;
				border-radius: 16rpx;
				font-size: 24upx;
				text-align: center;
				color: #FFFFFF;
			}
		}
		.add-btn {
			line-height: 70rpx;
			width: 222rpx !important;
			height: 70rpx;
			background: #26BCFD;
			border-radius: 16rpx;
			font-size: 24upx;
			text-align: center;
			color: #FFFFFF;
			margin: auto;
			margin-top: 20upx;
		}
		.meal-box {
			border: 1rpx solid #36355E;
			padding: 10upx;
			margin-top: 20upx;
			border-radius: 10upx;
		}

		.info-item {
			font-size: 28upx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 40upx;
			color: #FFFFFF;
			padding: 30upx 0;
			border-bottom: 1upx solid #36355E;
			align-items: flex-start;

			&:nth-last-of-type(1) {
				border-bottom: none;
			}

			.item-title {
				min-width: 140upx;
				flex: none;
			}

			.small {
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				margin: 0 40upx;
			}

			.set {
				flex: none;
				margin-left: 10upx;
				color: #26BCFD;
			}

			picker {
				flex: 1;
			}

			.select-input {
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #FFE577;
				flex: 1;
			}

			input {
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #FFE577;
				flex: 1;
			}

			textarea {
				background: #1D1C5C;
				border-radius: 16upx;
				padding: 30upx;
				height: 140upx;
				font-size: 24upx;
			}

			.textarea {
				background: #1D1C5C;
				border-radius: 16upx;
				padding: 30upx;
				height: 40upx;
				font-size: 24upx;
				width: 100%;
			}

			.icon-more {
				border-color: #FFFFFF;
			}

			.placeholderclass {
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #FFE577;
			}

			.select-box {
				flex-wrap: wrap;

				.select-item {
					font-size: 28upx;
					color: #FFFFFF;
					margin-bottom: 20upx;
					width: 50%;

					.select-icon {
						width: 48upx;
						height: 48upx;
						margin-right: 10upx;
					}
				}
			}
		}

		.remaks-box {
			font-size: 28rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			color: #82819B;
			line-height: 40rpx;
			padding-left: 118upx;
			margin-top: 12upx;
			text-decoration: underline;
		}
	}
	.Noborder{
		border: none !important;
	}
	.noPadd{
		padding:10upx 0 !important;
	}
	.remaks-box {
		font-size: 28rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #82819B;
		line-height: 40rpx;
		margin-top: 12upx;

		.icon-more {
			border-color: #82819B;
			width: 14upx;
			height: 14upx;
		}
	}

	.bottom-box {
		height: 120rpx;
		background: #1D1C5C;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		margin: auto;
		justify-content: center;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		z-index: 999;

		.define-btn {
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			line-height: 80rpx;
			width: 322rpx;
			height: 80rpx;
			background: #26BCFD;
			border-radius: 16rpx;
			text-align: center;
		}
	}
</style>